package vip.kqsy.cloud.ai.server.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import vip.kqsy.cloud.ai.server.mapper.AiSessionHistoryMapper;
import vip.kqsy.cloud.ai.server.pojo.dto.PageBySessionIdDTO;
import vip.kqsy.cloud.ai.server.pojo.entity.AiSessionHistory;
import vip.kqsy.cloud.ai.server.pojo.vo.PageBySessionIdVO;
import vip.kqsy.cloud.ai.server.service.AiSessionHistoryService;
import vip.kqsy.cloud.ai.server.utils.HtmlUtil;
import vip.kqsy.cloud.core.web.res.ResPage;

import java.util.List;

/**
 * <p>
 * 对话历史表 服务实现类
 * </p>
 *
 * @author cenjunjie
 * @since 2023-07-08
 */
@Service
public class AiSessionHistoryServiceImpl extends ServiceImpl<AiSessionHistoryMapper, AiSessionHistory> implements AiSessionHistoryService {

    @Override
    public ResPage<PageBySessionIdVO> pageBySessionId(PageBySessionIdDTO dto) {
        PageHelper.startPage(dto);
        List<AiSessionHistory> list = lambdaQuery()
                .eq(AiSessionHistory::getSessionId, dto.getSessionId())
                .orderByDesc(AiSessionHistory::getCreateTime)
                .list();
        return ResPage.of(list).convertListType(source -> {
            source.setContent(HtmlUtil.convert(source.getContent()));
            return BeanUtil.toBean(source, PageBySessionIdVO.class);
        });
    }

}
